const fs = require("fs");
const path = require("path");
const crypto = require("crypto");

const fileSize = 1024 * 1024 * 1024 * 2; // 设置文件大小为 2GB
const filePath = path.join(__dirname, "../output/", "largeFile.pdf"); // 设置文件路径

const fileStream = fs.createWriteStream(filePath);
fileStream.on("open", () => {
  console.log("File stream opened.");
});

let bytesWritten = 0;
const writeChunk = () => {
  // 写入1MB的随机数据
  const buffer = Buffer.alloc(1024 * 1024);
  crypto.randomFillSync(buffer);

  fileStream.write(buffer, () => {
    bytesWritten += buffer.length;
    if (bytesWritten < fileSize) {
      writeChunk();
    } else {
      fileStream.end();
      console.log("File written.");
    }
  });
};

writeChunk(); // 开始写入文件
